package vip.xiaonuo.modular.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Dict;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.core.context.login.LoginContextHolder;
import vip.xiaonuo.core.pojo.login.SysLoginUser;
import vip.xiaonuo.core.pojo.response.ErrorResponseData;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.modular.htagent.param.HtAgentParam;
import vip.xiaonuo.modular.htagent.service.HtAgentService;
import vip.xiaonuo.modular.hthotal.param.HtHotalParam;
import vip.xiaonuo.modular.hthotal.service.HtHotalService;
import vip.xiaonuo.modular.service.MySqlService;
import vip.xiaonuo.sys.modular.emp.param.SysEmpParam;
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
import vip.xiaonuo.sys.modular.org.param.SysOrgParam;
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
import vip.xiaonuo.sys.modular.user.param.SysUserParam;
import vip.xiaonuo.sys.modular.user.result.SysUserResult;
import vip.xiaonuo.sys.modular.user.service.SysUserDataScopeService;
import vip.xiaonuo.sys.modular.user.service.SysUserRoleService;
import vip.xiaonuo.sys.modular.user.service.SysUserService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
public class HtMainController {

    @Resource
    protected SysOrgService sysOrgService;

    @Resource
    protected SysUserService sysUserService;

    @Resource
    protected SysUserRoleService sysUserRoleService;

    @Resource
    protected SysUserDataScopeService sysUserDataScopeService;
    
    @Resource
    protected MySqlService mySqlServicel;

    @Resource
    private HtAgentService htAgentService;

    @Resource
    private HtHotalService htHotalService;

    /**
     * 获取当前等人的机构ID
     * @return
     */
    protected String getLoginOrgId(){
        SysLoginUser loginUser = LoginContextHolder.me().getSysLoginUser();
        String loginOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select public_org_id from ht_brand where public_user_id = '"+loginUser.getId()+"' "));
        if(loginOrgId==null||"null".equals(loginOrgId)||"".equals(loginOrgId)){
            loginOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select public_org_id from ht_agent where public_user_id = '"+loginUser.getId()+"' "));
        }
        return loginOrgId;
    }

    /**
     * 校验代理商数据
     * @param htAgentParam
     * @return
     */
    protected ErrorResponseData checkAgentData(HtAgentParam htAgentParam,String myId){
        String andSql = "";
        if(myId!=null){
            andSql = " id != '"+myId+"' and ";
        }
        Object viliName = mySqlServicel.getObjectBySql(" select id from ht_agent where "+andSql+" agentname = '"+htAgentParam.getAgentname().trim()+"' limit 0,1");
        if(viliName!=null){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"名称重复！");
        }
        Object viliPhone = mySqlServicel.getObjectBySql(" select id from ht_agent where "+andSql+" phone = '"+htAgentParam.getPhone().trim()+"' limit 0,1");
        if(viliPhone!=null){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"手机号重复！");
        }
        Object viliUserName = mySqlServicel.getObjectBySql(" select id from ht_agent where "+andSql+" username = '"+htAgentParam.getUsername().trim()+"' limit 0,1");
        if(viliUserName!=null){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"账号重复！");
        }
        return null;
    }

    /**
     * 保存代理商对于机构数据
     * @param htAgentParam
     * @param loginOrgId
     * @return
     */
    protected SysOrgParam saveAgentOrgData(HtAgentParam htAgentParam,String loginOrgId){
        SysOrgParam sysOrgParam = new SysOrgParam();
        String maxCode = String.valueOf(mySqlServicel.getObjectBySql(" select max(code)+1 from sys_org where pid = '"+loginOrgId+"' "));
        if("".equals(maxCode)||maxCode==null||"null".equals(maxCode))maxCode=""+(Long.parseLong(loginOrgId)+10001l);
        sysOrgParam.setCode(maxCode);//编号获取最大的编号
        sysOrgParam.setPid(Long.parseLong(loginOrgId));
        sysOrgParam.setName(htAgentParam.getAgentname()+"(代理)");
        String maxId = String.valueOf(mySqlServicel.getObjectBySql(" select max(id)+1 from sys_org where pid = '"+loginOrgId+"' "));
        if("".equals(maxId)||maxId==null||"null".equals(maxId))maxId=""+(Long.parseLong(loginOrgId)+10001l);
        sysOrgParam.setId(Long.parseLong(maxId));
        String maxSort = String.valueOf(mySqlServicel.getObjectBySql(" select max(sort)+1 from sys_org where pid = '"+loginOrgId+"' "));
        if("".equals(maxSort)||maxSort==null||"null".equals(maxSort)) maxSort="1";
        sysOrgParam.setSort(Integer.parseInt(maxSort));
        sysOrgParam.setRemark("system");
        sysOrgParam.setIsSystem(1);//此参数表示系统调用，能通过权限验证
        sysOrgService.add(sysOrgParam);
        return sysOrgParam;
    }

    /**
     * 保存代理商对于机构数据
     * @param htAgentParam
     * @return
     */
    protected SysOrgParam editAgentOrgData(HtAgentParam htAgentParam){
        String orgId = String.valueOf(mySqlServicel.getObjectBySql(" select public_org_id from ht_agent where id = '"+htAgentParam.getId()+"' "));
        SysOrgParam sysOrgParam = new SysOrgParam();
        sysOrgParam.setId(Long.parseLong(orgId));
        SysOrg sysOrg = sysOrgService.detail(sysOrgParam);
        BeanUtil.copyProperties(sysOrg, sysOrgParam);
        sysOrgParam.setName(htAgentParam.getAgentname()+"(代理)");
        sysOrgParam.setRemark("system");//此参数表示系统调用，能通过权限验证
        sysOrgParam.setIsSystem(1);//此参数表示系统调用，能通过权限验证
        sysOrgService.edit(sysOrgParam);
        return sysOrgParam;
    }

    /**
     * 保存代理商对于登录账号数据
     * @param htAgentParam
     * @param sysOrgParam
     * @return
     */
    protected SysUserParam saveAgentUserData(HtAgentParam htAgentParam,SysOrgParam sysOrgParam){
        SysUserParam sysUserParam = new SysUserParam();
        sysUserParam.setName(htAgentParam.getAgentname());
        sysUserParam.setAccount(htAgentParam.getUsername());
        sysUserParam.setPhone(htAgentParam.getPhone());
        sysUserParam.setNickName(htAgentParam.getAgentname());
        sysUserParam.setSex(1);
        sysUserParam.setIsSystem(1);
        SysEmpParam sysEmpParam = new SysEmpParam();
        sysEmpParam.setOrgId(sysOrgParam.getId());
        sysEmpParam.setId(sysUserParam.getId());
        sysEmpParam.setOrgName(sysOrgParam.getName());
        List<Dict> extIds = new ArrayList<Dict>();
        Dict dict = new Dict();
        dict.put("posId",1265476890672672787l);
        dict.put("orgId",sysOrgParam.getId());
        extIds.add(dict);
        sysEmpParam.setExtIds(extIds);
        List<Long> posIdList = new ArrayList<Long>();
        posIdList.add(1265476890672672787l);
        sysEmpParam.setPosIdList(posIdList);
        sysUserParam.setSysEmpParam(sysEmpParam);
        sysUserService.add(sysUserParam);
        String userId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_user where account = '"+htAgentParam.getUsername()+"' "));
        sysUserParam.setId(Long.parseLong(userId));
        return sysUserParam;
    }

    /**
     * 保存代理商对于登录账号数据
     * @param htAgentParam
     * @param sysOrgParam
     * @return
     */
    protected SysUserParam editAgentUserData(HtAgentParam htAgentParam,SysOrgParam sysOrgParam){
        String userId = String.valueOf(mySqlServicel.getObjectBySql(" select public_user_id from ht_agent where id = '"+htAgentParam.getId()+"' "));
        SysUserParam sysUserParam = new SysUserParam();
        sysUserParam.setId(Long.parseLong(userId));
        SysUserResult sysUser = sysUserService.detail(sysUserParam);
        BeanUtil.copyProperties(sysUser, sysUserParam);
        sysUserParam.setName(htAgentParam.getAgentname());
        sysUserParam.setAccount(htAgentParam.getUsername());
        sysUserParam.setPhone(htAgentParam.getPhone());
        sysUserParam.setNickName(htAgentParam.getAgentname());
        sysUserParam.setSex(1);
        sysUserParam.setIsSystem(1);//此参数表示系统调用，能通过权限验证
        SysEmpParam sysEmpParam = new SysEmpParam();
        sysEmpParam.setOrgId(sysOrgParam.getId());
        sysEmpParam.setId(sysUserParam.getId());
        sysEmpParam.setOrgName(sysOrgParam.getName());
        List<Dict> extIds = new ArrayList<Dict>();
        Dict dict = new Dict();
        dict.put("posId",1265476890672672787l);
        dict.put("orgId",sysOrgParam.getId());
        extIds.add(dict);
        sysEmpParam.setExtIds(extIds);
        List<Long> posIdList = new ArrayList<Long>();
        posIdList.add(1265476890672672787l);
        sysEmpParam.setPosIdList(posIdList);
        sysUserParam.setSysEmpParam(sysEmpParam);
        sysUserService.edit(sysUserParam);
        return sysUserParam;
    }

    /**
     * 保存授权数据已经角色信息
     * @param sysOrgParam
     * @param sysUserParam
     */
    protected void saveAgentRoloData(SysOrgParam sysOrgParam,SysUserParam sysUserParam){
        SysLoginUser loginUser = LoginContextHolder.me().getSysLoginUser();
        List<Long> grantRoleIdList = new ArrayList<Long>();
        /** 判断如果已经是二级代理,代理 */
        String roleCode = String.valueOf(mySqlServicel.getObjectBySql("select code from sys_role where id = (select role_id from sys_user_role where user_id = '"+loginUser.getId()+"' ) limit 0,1 "));
        String userRoleId = null;
        if("AGENT".equals(roleCode)){
            userRoleId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_role where code = 'AGENT2' "));
        }else if("BRAND".equals(roleCode)){
            userRoleId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_role where code = 'AGENT' "));
        }
        grantRoleIdList.add(Long.parseLong(userRoleId));
        List<Long> grantOrgIdList = new ArrayList<Long>();
        String userOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_org where pid = '"+sysOrgParam.getId()+"' "));
        if(userOrgId!=null){
            grantOrgIdList.add(Long.parseLong(userRoleId));
            userOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_org where pid = '"+sysOrgParam.getId()+"' "));
        }
        sysUserParam.setGrantOrgIdList(grantOrgIdList);
        sysUserParam.setGrantRoleIdList(grantRoleIdList);
        sysUserDataScopeService.grantData(sysUserParam);
        sysUserRoleService.grantRole(sysUserParam);
    }

    /***
     * 删除代理相关数据
     * @param htAgentParamList
     * @return
     */
    protected ResponseData removeAgentAllData(List<HtAgentParam> htAgentParamList){
        int deleteSize = htAgentParamList.size();
        int deleteCount = 0;
        for(HtAgentParam htAgentParam : htAgentParamList){
            /** 判断有没有下级 */
            String agentOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select public_org_id from ht_agent where id = '"+htAgentParam.getId()+"' "));
            String btAgentOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_org where pid = '"+agentOrgId+"' limit 0,1"));
            /** 没有下级，才执行删除命令 */
            if(btAgentOrgId==null||"null".equals(btAgentOrgId)||btAgentOrgId.isEmpty()){
                String userId = String.valueOf(mySqlServicel.getObjectBySql(" select public_user_id from ht_agent where id = '"+htAgentParam.getId()+"' "));
                /* 删除用户角色关系 */
                mySqlServicel.deleteSql("delete from sys_user_role where user_id = '"+userId+"' ");
                /* 删除用户机构关系 */
                mySqlServicel.deleteSql("delete from sys_user_data_scope where user_id = '"+userId+"' ");
                /* 删除用户 */
                mySqlServicel.deleteSql("delete from sys_user where id = '"+userId+"' ");
                /* 删除机构 */
                mySqlServicel.deleteSql("delete from sys_org where id = '"+agentOrgId+"' ");
                /* 删除代理 */
                List<HtAgentParam> deleteAgetn = new ArrayList<>();
                deleteAgetn.add(htAgentParam);
                htAgentService.delete(deleteAgetn);
                deleteCount++;
            }
        }
        if(deleteCount == 0 && deleteSize==1){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"有下级，不允许删除！");
        }else if(deleteCount > 0 && deleteSize>1){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"部分删除成功！");
        }else if(deleteCount == 0 && deleteSize>1){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"有下级，不允许删除！");
        }else{
            return new SuccessResponseData();
        }
    }

    /**
     * 设置用户密码
     * @param sysUserParam
     * @param newPass
     */
    protected void setUserPass(SysUserParam sysUserParam,String newPass){
        sysUserParam.setPassword("1oo111");
        sysUserParam.setNewPassword(newPass);
        sysUserService.updateSysPwd(sysUserParam);
    }


    /**
     * 校验酒店数据
     * @param htHotalParam
     * @param myId
     * @return
     */
    protected ErrorResponseData checkHotalData(HtHotalParam htHotalParam, String myId){
        String andSql = "";
        if(myId!=null){
            andSql = " id != '"+myId+"' and ";
        }
        Object viliName = mySqlServicel.getObjectBySql(" select id from ht_hotal where "+andSql+" hotalname = '"+htHotalParam.getHotalname().trim()+"' limit 0,1");
        if(viliName!=null){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"名称重复！");
        }
        Object viliPhone = mySqlServicel.getObjectBySql(" select id from ht_hotal where "+andSql+" phone = '"+htHotalParam.getPhone().trim()+"' limit 0,1");
        if(viliPhone!=null){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"手机号重复！");
        }
        Object viliUserName = mySqlServicel.getObjectBySql(" select id from ht_hotal where "+andSql+" username = '"+htHotalParam.getUsername().trim()+"' limit 0,1");
        if(viliUserName!=null){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"账号重复！");
        }
        return null;
    }

    /**
     * 保存代理商对于机构数据
     * @param htHotalParam
     * @param loginOrgId
     * @return
     */
    protected SysOrgParam saveHotalOrgData(HtHotalParam htHotalParam,String loginOrgId){
        SysOrgParam sysOrgParam = new SysOrgParam();
        String maxCode = String.valueOf(mySqlServicel.getObjectBySql(" select max(code)+1 from sys_org where pid = '"+loginOrgId+"' "));
        if("".equals(maxCode)||maxCode==null||"null".equals(maxCode))maxCode=""+(Long.parseLong(loginOrgId)+10001l);
        sysOrgParam.setCode(maxCode);//编号获取最大的编号
        sysOrgParam.setPid(Long.parseLong(loginOrgId));
        sysOrgParam.setName(htHotalParam.getHotalname()+"(网点)");
        String maxId = String.valueOf(mySqlServicel.getObjectBySql(" select max(id)+1 from sys_org where pid = '"+loginOrgId+"' "));
        if("".equals(maxId)||maxId==null||"null".equals(maxId))maxId=""+(Long.parseLong(loginOrgId)+10001l);
        sysOrgParam.setId(Long.parseLong(maxId));
        String maxSort = String.valueOf(mySqlServicel.getObjectBySql(" select max(sort)+1 from sys_org where pid = '"+loginOrgId+"' "));
        if("".equals(maxSort)||maxSort==null||"null".equals(maxSort)) maxSort="1";
        sysOrgParam.setSort(Integer.parseInt(maxSort));
        sysOrgParam.setRemark("system");
        sysOrgParam.setIsSystem(1);//此参数表示系统调用，能通过权限验证
        sysOrgService.add(sysOrgParam);
        return sysOrgParam;
    }


    /**
     * 保存酒店网点对于登录账号数据
     * @param htHotalParam
     * @param sysOrgParam
     * @return
     */
    protected SysUserParam saveHotalUserData(HtHotalParam htHotalParam,SysOrgParam sysOrgParam){
        SysUserParam sysUserParam = new SysUserParam();
        sysUserParam.setName(htHotalParam.getHotalname());
        sysUserParam.setAccount(htHotalParam.getUsername());
        sysUserParam.setPhone(htHotalParam.getPhone());
        sysUserParam.setNickName(htHotalParam.getHotalname());
        sysUserParam.setSex(1);
        sysUserParam.setIsSystem(1);
        SysEmpParam sysEmpParam = new SysEmpParam();
        sysEmpParam.setOrgId(sysOrgParam.getId());
        sysEmpParam.setId(sysUserParam.getId());
        sysEmpParam.setOrgName(sysOrgParam.getName());
        List<Dict> extIds = new ArrayList<Dict>();
        Dict dict = new Dict();
        dict.put("posId",1265476890672672787l);
        dict.put("orgId",sysOrgParam.getId());
        extIds.add(dict);
        sysEmpParam.setExtIds(extIds);
        List<Long> posIdList = new ArrayList<Long>();
        posIdList.add(1265476890672672787l);
        sysEmpParam.setPosIdList(posIdList);
        sysUserParam.setSysEmpParam(sysEmpParam);
        sysUserService.add(sysUserParam);
        String userId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_user where account = '"+htHotalParam.getUsername()+"' "));
        sysUserParam.setId(Long.parseLong(userId));
        return sysUserParam;
    }

    /**
     * 保存授权数据已经角色信息
     * @param sysOrgParam
     * @param sysUserParam
     */
    protected void saveHotalRoloData(SysOrgParam sysOrgParam,SysUserParam sysUserParam){
        SysLoginUser loginUser = LoginContextHolder.me().getSysLoginUser();
        List<Long> grantRoleIdList = new ArrayList<Long>();
//        /** 判断如果已经是二级代理,代理 */
//        String roleCode = String.valueOf(mySqlServicel.getObjectBySql("select code from sys_role where id = (select role_id from sys_user_role where user_id = '"+loginUser.getId()+"' ) limit 0,1 "));
        String userRoleId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_role where code = 'HOTAL' "));
        grantRoleIdList.add(Long.parseLong(userRoleId));
        List<Long> grantOrgIdList = new ArrayList<Long>();
        String userOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_org where pid = '"+sysOrgParam.getId()+"' "));
        if(userOrgId!=null){
            grantOrgIdList.add(Long.parseLong(userRoleId));
            userOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_org where pid = '"+sysOrgParam.getId()+"' "));
        }
        sysUserParam.setGrantOrgIdList(grantOrgIdList);
        sysUserParam.setGrantRoleIdList(grantRoleIdList);
        sysUserDataScopeService.grantData(sysUserParam);
        sysUserRoleService.grantRole(sysUserParam);
    }


    /***
     * 删除酒店网点相关数据
     * @param htHotalParamList
     * @return
     */
    protected ResponseData removeHotalAllData(List<HtHotalParam> htHotalParamList){
        int deleteSize = htHotalParamList.size();
        int deleteCount = 0;
        for(HtHotalParam htHotalParam : htHotalParamList){
            /** 判断有没有下级 */
            String agentOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select public_org_id from ht_hotal where id = '"+htHotalParam.getId()+"' "));
            String btAgentOrgId = String.valueOf(mySqlServicel.getObjectBySql(" select id from sys_org where pid = '"+agentOrgId+"' limit 0,1"));
            /** 没有下级，才执行删除命令 */
            if(btAgentOrgId==null||"null".equals(btAgentOrgId)||btAgentOrgId.isEmpty()){
                String userId = String.valueOf(mySqlServicel.getObjectBySql(" select public_user_id from ht_hotal where id = '"+htHotalParam.getId()+"' "));
                /* 删除用户角色关系 */
                mySqlServicel.deleteSql("delete from sys_user_role where user_id = '"+userId+"' ");
                /* 删除用户机构关系 */
                mySqlServicel.deleteSql("delete from sys_user_data_scope where user_id = '"+userId+"' ");
                /* 删除用户 */
                mySqlServicel.deleteSql("delete from sys_user where id = '"+userId+"' ");
                /* 删除机构 */
                mySqlServicel.deleteSql("delete from sys_org where id = '"+agentOrgId+"' ");
                /* 删除代理 */
                List<HtHotalParam> deleteHotal = new ArrayList<>();
                deleteHotal.add(htHotalParam);
                htHotalService.delete(deleteHotal);
                deleteCount++;
            }
        }
        if(deleteCount == 0 && deleteSize==1){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"有下级，不允许删除！");
        }else if(deleteCount > 0 && deleteSize>1){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"部分删除成功！");
        }else if(deleteCount == 0 && deleteSize>1){
            return new ErrorResponseData(ResponseData.DEFAULT_ERROR_CODE,"有下级，不允许删除！");
        }else{
            return new SuccessResponseData();
        }
    }

    /**
     * 保存酒店网点对于机构数据
     * @param htHotalParam
     * @return
     */
    protected SysOrgParam editHotalOrgData(HtHotalParam htHotalParam){
        String orgId = String.valueOf(mySqlServicel.getObjectBySql(" select public_org_id from ht_hotal where id = '"+htHotalParam.getId()+"' "));
        SysOrgParam sysOrgParam = new SysOrgParam();
        sysOrgParam.setId(Long.parseLong(orgId));
        SysOrg sysOrg = sysOrgService.detail(sysOrgParam);
        BeanUtil.copyProperties(sysOrg, sysOrgParam);
        sysOrgParam.setName(htHotalParam.getHotalname()+"(网点)");
        sysOrgParam.setRemark("system");//此参数表示系统调用，能通过权限验证
        sysOrgParam.setIsSystem(1);//此参数表示系统调用，能通过权限验证
        sysOrgService.edit(sysOrgParam);
        return sysOrgParam;
    }

    /**
     * 保存酒店网点对于登录账号数据
     * @param htHotalParam
     * @param sysOrgParam
     * @return
     */
    protected SysUserParam editHotalUserData(HtHotalParam htHotalParam,SysOrgParam sysOrgParam){
        String userId = String.valueOf(mySqlServicel.getObjectBySql(" select public_user_id from ht_hotal where id = '"+htHotalParam.getId()+"' "));
        SysUserParam sysUserParam = new SysUserParam();
        sysUserParam.setId(Long.parseLong(userId));
        SysUserResult sysUser = sysUserService.detail(sysUserParam);
        BeanUtil.copyProperties(sysUser, sysUserParam);
        sysUserParam.setName(htHotalParam.getHotalname());
        sysUserParam.setAccount(htHotalParam.getUsername());
        sysUserParam.setPhone(htHotalParam.getPhone());
        sysUserParam.setNickName(htHotalParam.getHotalname());
        sysUserParam.setSex(1);
        sysUserParam.setIsSystem(1);//此参数表示系统调用，能通过权限验证
        SysEmpParam sysEmpParam = new SysEmpParam();
        sysEmpParam.setOrgId(sysOrgParam.getId());
        sysEmpParam.setId(sysUserParam.getId());
        sysEmpParam.setOrgName(sysOrgParam.getName());
        List<Dict> extIds = new ArrayList<Dict>();
        Dict dict = new Dict();
        dict.put("posId",1265476890672672787l);
        dict.put("orgId",sysOrgParam.getId());
        extIds.add(dict);
        sysEmpParam.setExtIds(extIds);
        List<Long> posIdList = new ArrayList<Long>();
        posIdList.add(1265476890672672787l);
        sysEmpParam.setPosIdList(posIdList);
        sysUserParam.setSysEmpParam(sysEmpParam);
        sysUserService.edit(sysUserParam);
        return sysUserParam;
    }
}
